using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Query;
using Microsoft.AspNetCore.OData.Results;
using Microsoft.AspNetCore.OData.Routing.Controllers;
using OData.Data;
using OData.Shared.Models;

namespace OData.WebApi.Controller.v1;

[ApiVersion("1.0")]
public class LineItemsController(ApplicationDbContext context) : ODataController
{
	[EnableQuery]
	public IQueryable<LineItem> Get()
	{
		return context.LineItems;
	}

	[EnableQuery]
	public SingleResult<LineItem> Get([FromRoute] int key)
	{
		var result = context.LineItems.Where(l => l.Id == key);
		return SingleResult.Create(result);
	}
}
